﻿#include "Framework/CommonHead.h"

#include "ScriptCompiler/Compiler.h"
#include "ScriptCompiler/CompileResult.h"

#include "File/FileUtils.h"
#include "Path/Paths.h"

#include "ScriptRuntime/ScriptSubsystem.h"

#include "TestScriptInheriableObject.h"

#include "Output/Console.h"

#include "Containers/String.h"
#include "Asset/AssetPackage.h"
#include "Asset/AssetSubsystem.h"

int main(int argc, char* argv[])
{  
   auto App=NewObject<RApplication>();
    

   SApplicationArgument Arguments;
   Arguments.ExecutablePath=SPath(argv[0]);
   Arguments.WorkThreadNum=4;
   Arguments.ContentDirectory=Arguments.ExecutablePath.Parent()/U"Content/ScriptRunner";

   App->Initialize(Arguments);

   //register project package
   {
      SAssetPackage ProjectPackage;
      ProjectPackage.Name=U"Content";
      ProjectPackage.Path=SPaths::GetContentDirectory().ToString();

      RAssetSubsystem::Get()->AddPackage(ProjectPackage);
   }

   TVector<SPath> ScriptPaths;
   ScriptPaths.Add(SPaths::GetContentDirectory()/U"TestSimpleProgram.gs");
   
   auto Result=WH::Compile(ScriptPaths);
   Result.ErrorInfo.Print();

   if(Result.ErrorInfo.IsErrorOccured())
   {
      return 0;
   }
   
   App->GetSubsystem<RScriptSubsystem>()->LoadScript(Result.ByteCode,U"ScriptRunnerScript");

   //App->GetSubsystem<RScriptSubsystem>()->StartDebugServer(3988);
      
   App->GetSubsystem<RScriptSubsystem>()->InvokeStaticFunction(U"ConsoleApplication1::Program",U"Test",{});
 
   
   App->Run();

}